/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sales.hanserver.action.hancadpo.insertproduct.query;

import br.com.sales.hanserver.action.hancadpo.consts.HanCadPOServerConsts;
import br.com.sales.hanserver.action.hancadsa.finished.query.FinishedSaleQuery;
import br.com.sales.hanserver.dao.Dao;
import static br.com.sales.hanserver.dao.Dao.closeConn;
import static br.com.sales.hanserver.dao.Dao.getConn;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author v
 */
public class InsertProductQuery extends Dao {

    public InsertProductQuery() {
    }

    protected void insertProduct(String ds_produto, Double vl_compra, Double vl_venda,
            Double vl_promocional, Double pr_margem_lucro, Integer qt_estoque,
            Integer qt_min_estoque, Integer qt_max_estoque, String ds_breve, Long nr_seq_pf,
            String ie_estoque, Timestamp dt_registro) {
        try {

            PreparedStatement preparedStmt = getConn().prepareStatement(HanCadPOServerConsts.INSERT_PRODUCT);
            preparedStmt.setString(1, ds_produto);
            preparedStmt.setObject(2, vl_compra);
            preparedStmt.setObject(3, vl_venda);
            preparedStmt.setObject(4, vl_promocional);
            preparedStmt.setObject(5, pr_margem_lucro);
            preparedStmt.setObject(6, qt_estoque);
            preparedStmt.setObject(7, qt_min_estoque);
            preparedStmt.setObject(8, qt_max_estoque);
            preparedStmt.setString(9, ds_breve);
            preparedStmt.setObject(10, nr_seq_pf);
            preparedStmt.setString(11, ie_estoque);
            preparedStmt.setTimestamp(12, dt_registro);

            preparedStmt.executeUpdate();

        } catch (Exception e) {
            Logger.getLogger(FinishedSaleQuery.class.getName()).log(Level.SEVERE, "Error insert products", e);
        } finally {
            closeConn();
        }
    }

    protected void updateProduct(String ds_produto, Double vl_compra, Double vl_venda,
            Double vl_promocional, Double pr_margem_lucro, Integer qt_estoque,
            Integer qt_min_estoque, Integer qt_max_estoque, String ds_breve, Long nr_seq_pf,
            String ie_estoque, Timestamp dt_registro, long sequence) {
        try {

            PreparedStatement preparedStmt = getConn().prepareStatement(HanCadPOServerConsts.UPDATE_PRODUCT);
            preparedStmt.setString(1, ds_produto);
            preparedStmt.setObject(2, vl_compra);
            preparedStmt.setObject(3, vl_venda);
            preparedStmt.setObject(4, vl_promocional);
            preparedStmt.setObject(5, pr_margem_lucro);
            preparedStmt.setObject(6, qt_estoque);
            preparedStmt.setObject(7, qt_min_estoque);
            preparedStmt.setObject(8, qt_max_estoque);
            preparedStmt.setString(9, ds_breve);
            preparedStmt.setObject(10, nr_seq_pf);
            preparedStmt.setString(11, ie_estoque);
            preparedStmt.setTimestamp(12, dt_registro);
            preparedStmt.setLong(13, sequence);

            preparedStmt.executeUpdate();

        } catch (Exception e) {
            Logger.getLogger(FinishedSaleQuery.class.getName()).log(Level.SEVERE, "Error insert products", e);
        } finally {
            closeConn();
        }
    }

}
